#ifndef __LOG_H__
#define __LOG_H__

#include "define.h"
#include "thread.h"
#include "ioManager.h"
#include "mempool.h"
#include <iostream>
#include <map>
#include <time.h>



//日志管理的上下文;
struct logManger_st
{
	pthread_t logtid;
	MemPool mem; //内存管理;
	int accessLogFd; //访问日志的文件描述符;
	int errorLogFd; //错误日志的文件描述符;
	char * accessLogPath;
	char * errorLogPath;
	int logLevel;
	ioModel *io;
	char *logbuf;
	int bufSize;
	int ioType;
	int stopFlag;
};


#define  GETTIME(x, y) do { \
	time(&(y)); 			\
	(x)=localtime(&(y));    \
}while(0)


//日志管理类;
class LogManger{
	public:
		~LogManger(){};
		static LogManger * getInstance();
		static void * LogWriteRun(void *arg);
		int LogInit(confMgr *conf, std::vector<int> &logVec);
		static int LogFormatAndSend(int fd, int type, char *pbuf, const char *format,...);
		struct logManger_st & getLogOptCtx(){ return this->logst; }
		int handleLogWrite(int count);
	private:
		static LogManger * logMsg;
		struct logManger_st logst;
		struct log_conf_st logconf;
		LogManger(){ };
		class Garbage{
			public:
				~Garbage(){
					if(LogManger::logMsg){
						delete LogManger::logMsg;
					}
				}
		};
		static Garbage gg;  //垃圾回收类的静态对象;
};

#endif 
